package com.tledu.email.service.impl;

import java.util.Collections;
import java.util.Date;
import java.util.List;

import com.tledu.common.core.domain.entity.SysDept;
import com.tledu.common.core.domain.entity.SysUser;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.utils.DateUtils;
import com.tledu.common.utils.SecurityUtils;
import com.tledu.system.service.ISysDeptService;
import com.tledu.system.service.ISysUserService;
import jdk.nashorn.internal.ir.Symbol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tledu.email.mapper.EmailTableMapper;
import com.tledu.email.domain.EmailTable;
import com.tledu.email.service.IEmailTableService;

/**
 * 邮箱Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-29
 */
@Service
public class EmailTableServiceImpl implements IEmailTableService {
    @Autowired
    private EmailTableMapper emailTableMapper;
    @Autowired
    private ISysUserService userService;
    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询邮箱
     *
     * @param id 邮箱主键
     * @return 邮箱
     */
    @Override
    public EmailTable selectEmailTableById(Long id) {
        return emailTableMapper.selectEmailTableById(id);
    }

    /**
     * 查询邮箱列表
     *
     * @param emailTable 邮箱
     * @return 邮箱
     */
    @Override
    public List<EmailTable> selectEmailTableList(EmailTable emailTable) {
        return emailTableMapper.selectEmailTableList(emailTable);
    }

    /**
     * 新增邮箱
     *
     * @param emailTable 邮箱
     * @return 结果
     */
    @Override
    public int insertEmailTable(EmailTable emailTable) {
        emailTable.setCreateTime(DateUtils.getNowDate());
        return emailTableMapper.insertEmailTable(emailTable);
    }

    /**
     * 修改邮箱
     *
     * @param emailTable 邮箱
     * @return 结果
     */
    @Override
    public int updateEmailTable(EmailTable emailTable) {
        emailTable.setUpdateTime(DateUtils.getNowDate());
        return emailTableMapper.updateEmailTable(emailTable);
    }

    /**
     * 批量删除邮箱
     *
     * @param ids 需要删除的邮箱主键
     * @return 结果
     */
    @Override
    public int deleteEmailTableByIds(Long[] ids) {
        return emailTableMapper.deleteEmailTableByIds(ids);
    }

    /**
     * 删除邮箱信息
     *
     * @param id 邮箱主键
     * @return 结果
     */
    @Override
    public int deleteEmailTableById(Long id) {
        return emailTableMapper.deleteEmailTableById(id);
    }

    // 查询当前用户收件箱的内容
    @Override
    public List<EmailTable> selectInboxList(EmailTable emailTable) {
        // 收件人id=当前用户id
        Long userId = SecurityUtils.getUserId();
        emailTable.setRecipientsId(userId);
        return emailTableMapper.selectInboxList(emailTable);
    }

    @Override
    public int changeStatus(Long id) {
        return emailTableMapper.changeStatus(id);
    }

    // 根据条件动态筛选用户收件箱的内容
    @Override
    public List<EmailTable> selectByCondition(EmailTable emailTable) {
        Long userId = SecurityUtils.getUserId();
        emailTable.setRecipientsId(userId);
        return emailTableMapper.selectByCondition(emailTable);
    }

    // 逻辑删除邮箱
    @Override
    public int updateSymbol(Long[] ids) {
        return emailTableMapper.updateSymbol(ids);
    }
}
